// 引入pinia 组件
import {defineStore} from 'pinia'
// ref
import { ref } from "vue"
import { getLoginUserUsingGet } from '@/api/userController'
export const useLoginUserStore = defineStore("loginUser",()=>{
  const loginUser = ref<API.LoginUserVO>({
    userName:"未登录",
    userAvatar:""
  })
  //获取当前用户
  async function fetchLoginUser(){
    const res = await getLoginUserUsingGet();
    if (res.data.code === 0 && res.data.data){
      loginUser.value = res.data.data
    }
  }



  //缓存用户信息
  function setLoginUser(newLoginUser:any){
    loginUser.value = newLoginUser
  }
//返回pinia
  return {loginUser, fetchLoginUser,setLoginUser}
})
